﻿using System;
using System.Windows.Forms;
using System.Configuration;
using AutomatedDatabaseDR;

namespace SqlServerDRControlPanel
{
    public partial class AddPostScript : Form
    {
        private string m_DatabaseName;

        public AddPostScript(string databaseName)
        {
            InitializeComponent();
            m_DatabaseName = databaseName;
        }

        private void AddPostScript_Load(object sender, EventArgs e)
        {
            this.Text = string.Format("Add Post Action Script for: {0}", m_DatabaseName);
        }

        private void Cancel_btn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void PostScript_btn_Click(object sender, EventArgs e)
        {
            string ConfigServer = ConfigurationManager.AppSettings["ConfigDbConn"];
            string[] ConfigItems = ConfigServer.Split('|');
            ConfigItems ci = new ConfigItems(ConfigItems[0], ConfigItems[1]);


            try
            {
                ci.InsertPostActions(m_DatabaseName, this.PostScriptSql_tb.Text);
                MessageBox.Show("Insert Complete", "Insert Complete", MessageBoxButtons.OK);
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Insert Error", MessageBoxButtons.OK);
            }
        }
    }
}
